<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <meta http-equiv="X-UA-Compatible" content="ie=edge">
    <title>Vue-element结合作业</title>
    <!-- 引入样式 -->
    <link rel="stylesheet" href="https://unpkg.com/element-ui/lib/theme-chalk/index.css">
    <script src="./vue.min.js"></script>
    <script src="./jquery.min.js"></script>
    <!-- 引入组件库 -->
    <script src="https://unpkg.com/element-ui/lib/index.js"></script>
    <style>
        a{
            text-decoration: none;
            color:black;
        }
        .content{
           width:70%;
            margin:30px auto;
        }
    </style>
</head>

<body>
    <div id="app"></div>
    <template id="main">
        <div class="content">
            <h1>学生信息表</h1>
            <el-table :data="users" border style="width: 100%">
                <el-table-column fixed prop="id" label="编号" width="150">
                </el-table-column>
                <el-table-column prop="username" label="姓名" width="120">
                </el-table-column>
                <el-table-column prop="phone" label="电话" width="120">
                </el-table-column>
                <el-table-column prop="age" label="年龄" width="120">
                </el-table-column>
                <el-table-column prop="email" label="邮箱" width="300">
                </el-table-column>
                <el-table-column prop="birth" label="生日" width="300">
                </el-table-column>
                <el-table-column fixed="right" label="操作" width="100">
                    <template slot-scope="scope">
                        <el-button @click="handleClick(scope.row), del(scope.row.id)" type="text" size="small">删除</el-button>
                        <a :href="'edit.html#'+scope.row.id">编辑</a>
                    </template>
                </el-table-column>
            </el-table>
            <el-row>
              
                <el-button type="primary" round> <a href="add.html">添加学生信息</a></el-button>
            </el-row>
        </div>
    </template>
</body>
<script>
    var vm = new Vue({
        el: '#app',
        template: '#main',
        created: function () {
            this.getUsers();
        },
        data: function () {
            return {
                users: [],
            }
        },
        methods: {
            handleClick: function (row) {
                console.log(row);
            },
            del: function (id) {
                var that = this;
                that.$confirm('此操作将永久删除该文件, 是否继续?', '提示', {
                    confirmButtonText: '确定',
                    cancelButtonText: '取消',
                    type: 'warning',
                    center: true,
                }).then(function () {
                    $.get('/users/del', { id: id }).done(function () {
                        location.reload();
                        that.$message({
                            type: 'success',
                            message: '删除成功!'
                        });
                    })
                    }).catch(function () {
                        that.$message({
                            type: 'info',
                            message: '已取消删除'
                        });
                    });
            },
            getUsers: function () {
                var that = this;
                $.get('/users/index', { id: this.id }).done(function (result) {
                    that.users = result;
                });
            },
        },
    })
</script>

</html>